<%-- 
    Document   : NDefuncion
    Created on : 16-sep-2013, 15:19:52
    Author     : WALDIR
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="com.ptr.ptrsystem.dao.Lista" %>
<%@page import="com.ptr.ptrsystem.bean.*"%>
<%@page import="java.util.LinkedList" %>
<%@page language="java" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Registro De Defuncion</title>
        <link rel="stylesheet" type="text/css" href="/RegCivil/css/estilos.css">
        <link rel="stylesheet" type="text/css" href="/RegCivil/datepicker/css/cupertino/jquery-ui-1.10.3.custom.min.css"/>
        <script type="text/javascript" src="/RegCivil/datepicker/jquery-1.9.1.js"></script>
        <script type="text/javascript" src="/RegCivil/datepicker/jquery-ui-1.10.3.custom.min.js"></script>
        <script type="text/javascript" src="/RegCivil/calendario/calendario.js"></script>
        <script type="text/javascript">
            if (window.ActiveXObject) {
                var obj = new ActiveXObject("Microsoft.XMLHTTP");
            }
            if (window.XMLHttpRequest) {
                var obj = new XMLHttpRequest();
            }
            //verifica defuncion
            function verificarMatrimonio()
            {
                var vcodigo = document.getElementById("codper").value;
                obj.onreadystatechange = function() {
                    if (obj.readyState == 4)
                    {
                        var json = eval("(" + obj.responseText + ")");
                        if (json.mensage == 'SI')
                        {
                            document.getElementById("NACDE").value = json.nActa;
                            document.getElementById("FechRegDe").value = json.fechaR;
                            document.getElementById("FechDe").value = json.fecha;
                            document.getElementById("nrolibro").value = json.nlibro;
                            document.getElementById("nombreubigeo").value = json.nubigeo;
                            alert("IA EXISTE UN CDEF DE LA PERSONA");
                        }else{
                            document.getElementById("NACDE").value = "";
                            document.getElementById("FechRegDe").value = "";
                            document.getElementById("FechDe").value = "";
                            document.getElementById("nrolibro").value = "";
                            document.getElementById("nombreubigeo").value = "";
                        }
                    }
                };
                obj.open("post", "${pageContext.request.contextPath}/DefuncionAjax", true);
                obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                obj.send("codpersona=" + vcodigo);
            }
            ///


            function mostrarNombre(boton)
            {
                var btn = boton;
                var CodPer = document.getElementById("codper");
                var nroActacdef = document.getElementById("NACDE");
                var fechRegdef = document.getElementById("FechRegDe");
                //ubigeo matrimonial
                var dep = document.getElementById("dep");
                var prov = document.getElementById("pro");
                var dist = document.getElementById("dis");
                var otro = document.getElementById("otr");
                //
                var codLugOcurr = document.getElementById("codLugO");
                var hor = document.getElementById("hor");
                var min = document.getElementById("minut");
                var seg = document.getElementById("segund");
                var fechdef = document.getElementById("FechDe");
                var dniM = document.getElementById("dniMADRE").value;
                var dniP = document.getElementById("dniPADRE").value;
                var dniDE = document.getElementById("dniDECLARANTE").value;
                var dniPR = document.getElementById("dniPERSREG").value;
                var codEst = document.getElementById("codEst");
                var codtdoc = document.getElementById("codtdoc");
                var rutActadef = document.getElementById("rutActaDe");
                var rutActadef2 = document.getElementById("rutActaDe2");
                var obs = document.getElementById("ob");
                var NroLib = document.getElementById("nrolibro").value;
                var txt = "btn1=" + btn + "&codpersona=" + CodPer + "&NACDEF=" + nroActacdef + "&NroLibro=" + NroLib +
                        "&FechRegDef=" + fechRegdef + "&dep=" + dep + "&prov=" + prov + "&dist="
                        + dist + "&otro=" + otro + "&CodLugOcurr=" + codLugOcurr + "&FecDef=" + fechdef
                        + "&hor=" + hor + "&min=" + min + "&seg=" + seg + "&DNIMadre=" + dniM +
                        "&DNIPadre=" + dniP + "&DNIDecl=" + dniDE + "&DNIPerReg=" + dniPR + "&CodEst=" +
                        codEst + "&CodTDoc=" + codtdoc + "&Obs=" + obs + "&RutActDef=" + rutActadef + "&RutActDef2=" + rutActadef2;

                if (btn == "mostrarMADRE")
                {
                    obj.onreadystatechange = function() {
                        document.getElementById("madre").value= obj.responseText;
                    };
                }
                if (btn == "mostrarPADRE")
                {
                    obj.onreadystatechange = function() {
                        document.getElementById("padre").value=obj.responseText;
                    };
                }
                if (btn == "mostrarDECLARANTE")
                {
                    obj.onreadystatechange = function() {
                        document.getElementById("DECLARANTE").value= obj.responseText;
                    };
                }
                if (btn == "mostrarPERSONAREG")
                {
                    obj.onreadystatechange = function() {
                        document.getElementById("registrador").value= obj.responseText;
                    };
                }
                obj.open("post", "${pageContext.request.contextPath}/MantenimientoDefuncion", true);
                obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                obj.send(txt);
            }
        </script>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#NAVUbigeo").dialog({
                    autoOpen: false,
                    modal: true,
                    height: 300,
                    width: 900,
                    show: "slide",
                    hide: "slide",
                    draggable: false
                });
            });
            $(document).ready(function() {
                $("#shwUbigeo").click(function() {
                    $("#NAVUbigeo").dialog("open");
                });
            });
        </script>
        <script type="text/javascript">
            function selectUbigeo(btn)
            {
                var UBI = btn.value;
                var iddep = document.getElementById(UBI).getElementsByTagName('td')[0].innerHTML;
                var idpro = document.getElementById(UBI).getElementsByTagName('td')[1].innerHTML;
                var iddis = document.getElementById(UBI).getElementsByTagName('td')[2].innerHTML;
                var idotr = document.getElementById(UBI).getElementsByTagName('td')[3].innerHTML;
                var dep = document.getElementById(UBI).getElementsByTagName('td')[4].innerHTML;
                var pro = document.getElementById(UBI).getElementsByTagName('td')[5].innerHTML;
                var dis = document.getElementById(UBI).getElementsByTagName('td')[6].innerHTML;
                var otr = document.getElementById(UBI).getElementsByTagName('td')[7].innerHTML;
                var ubi = dep + " - " + pro + " - " + dis + " " + otr;
                document.getElementById("dep").value=iddep;
                document.getElementById("pro").value= idpro;
                document.getElementById("dis").value= iddis;
                document.getElementById("otr").value=idotr;
                document.getElementById("nombreubigeo").value= ubi;
                $("#NAVUbigeo").dialog("close");
            }
        </script>
        <script type="text/javascript">
            function AUbigeo(btn)
            {
                var dep = document.getElementById("Tdep").value;
                var pro = document.getElementById("Tpro").value;
                var dis = document.getElementById("Tdis").value;
                var otr = document.getElementById("Totr").value;
                var txt = "boton=" + btn + "&Tdepartamento=" + dep + "&Tprovincia=" + pro + "&Tdistrito=" + dis +
                        "&Totro=" + otr;
                if (btn == "Ubigeo")
                {
                    obj.onreadystatechange = function() {
                        document.getElementById("listaU").innerHTML = obj.responseText;
                    };
                }
                obj.open("post", "${pageContext.request.contextPath}/BusquedaUbigeo", true);
                obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                obj.send(txt);
            }
        </script>

    </head>
    <body>
        <form action="${pageContext.request.contextPath}/MantenimientoDefuncion" name="" method="post" class="contacto">
            <table align="center" border="0" cellspacing="0" cellpadding="0" style="margin-top:0px ">
                <tr>
                    <td>
                        <fieldset style="alignment-baseline: central" >
                            <legend style="border: 1px solid #dce0e3;background-color: #edf1f5">REGISTRO DE DEFUNCION</legend>
                            <table border="0">
                                <tr>
                                    <td>
                                        <fieldset><legend><label/>REGISTRO PERSONAL</legend>
                                            <table>
                                                <tr>
                                                    <td><label/>Cod Persona</td>
                                                    <td><input type="text" name="codpersona" id="codper" required maxlength="8" pattern="^\d{8}" style="width: 150px;">
                                                    </td>
                                                    <td><input type="button" name="busqueda" value="BUSCAR..." onclick="verificarMatrimonio()" style="width: 150px;height: 30px;">
                                                    </td>

                                                </tr>
                                                <tr>
                                                    <td><label/>Nro Acta CDEF</td>
                                                    <td><input type="text" name="NACDEF" id="NACDE" required maxlength="8" pattern="^\d{8}" style="width: 140px;">
                                                    </td>
                                                    <td><label/>Nro De Libro</td>
                                                    <td><input type="text" name="NroLibro" id="nrolibro" required style="width: 70px;">
                                                    </td>
                                                </tr>
                                                <tr>  
                                                    <td><label/>Fecha De Registro De Defuncion</td>
                                                    <td><input type="text" name="FechRegDef" id="FechRegDe" required maxlength="10" class="tx_fecha" style="width: 150px;">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="6">
                                                        <fieldset style="padding-left:20px;">
                                                            <legend>Ubigeo</legend>
                                                            <table border="0">
                                                                <tr>
                                                                    <td><input type="text" name="dep" id="dep" size="2"  style="width: 1.0em" maxlength="2"></td>
                                                                    <td><input type="text" name="prov" id="pro" size="2"  style="width: 1.0em" maxlength="2"></td>
                                                                    <td><input type="text" name="dist" id="dis" size="2"  style="width: 1.0em" maxlength="2"></td>
                                                                    <td><input type="text" name="otro" id="otr" size="2"  style="width: 1.0em" maxlength="2"></td>
                                                                    <td><input type="text" name="lugar_m" id="nombreubigeo" style="width: 45.0em"><button type="button" style="width: 3em;margin-left: 5px;" id="shwUbigeo" >:::</button>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </fieldset>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td><label/>Cod Lugar De Ocurrencia</td>
                                                    <td colspan="2"><select name="CodLugOcurr" id="codLugO" style="padding: 7px 6px;
                                                                            width: 130px;
                                                                            border: 1px solid #CED5D7;
                                                                            resize: none;
                                                                            box-shadow:0 0 0 3px #EEF5F7;
                                                                            margin: 5px 0;
                                                                            text-transform: uppercase;">
                                                            <% LinkedList<LugarOcurrencia> lisLugOc = Lista.getListaLugarOcurr();
                                                                for (int i = 0; i < lisLugOc.size(); i++) {%>
                                                            <option value="<%=lisLugOc.get(i).getCOD_LUGAR_OCURR()%>"><%=lisLugOc.get(i).getNOM_CEN_LIG_OCU()%></option>  
                                                            <%}%>
                                                        </select>
                                                    </td>
                                                    <td><label/>Hora De Defuncion</td>
                                                    <td><input type="text" name="hor" id="hor" maxlength="2" placeholder="hh" pattern="^\d{2}" style="width: 30px;">&nbsp;:
                                                        <input type="text" name="min"  id="minut" maxlength="2" placeholder="mm" pattern="^\d{2}" style="width: 30px;">&nbsp;:
                                                        <input type="text" name="seg" id="segund" maxlength="2" placeholder="ss" pattern="^\d{2}" style="width: 30px;">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td><label/>Fecha De Defuncion</td>
                                                    <td><input type="text" name="FecDef" id="FechDe" maxlength="10" class="tx_fecha" style="width: 120px;">
                                                    </td>
                                                </tr>
                                            </table>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>DATOS DE LOS PADRES</legend>
                                            <table border="0">
                                                <tr>
                                                    <td><label/>DNI De La Madre</td>
                                                    <td><input type="text" name="DNIMadre" id="dniMADRE" maxlength="8"  pattern="^\d{8}" style="width: 180px;">
                                                        <button type="button" style="width: 3em" onclick="mostrarNombre('mostrarMADRE')">:::</button>
                                                    </td>
                                                    <td colspan="4"><input type="text" name="nomMadre" id="madre" style="width: 450px;font-weight: bold;">
                                                    </td>
                                                </tr><tr>
                                                    <td><label/>DNI Del Padre</td>
                                                    <td><input type="text" name="DNIPadre" id="dniPADRE" maxlength="8"  pattern="^\d{8}" style="width: 180px;">
                                                        <button type="button" style="width: 3em" onclick="mostrarNombre('mostrarPADRE')">:::</button>
                                                    </td>
                                                    <td colspan="4"><input type="text" name="nomPadre" id="padre"  style="width: 450px;font-weight: bold;">
                                                    </td>
                                                </tr>
                                            </table>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>DATOS DE REGISTRO</legend>
                                            <table border="0">
                                                <tr>
                                                    <td><label/>DNI Declarante</td>
                                                    <td><input type="text" name="DNIDecl" id="dniDECLARANTE" maxlength="8"  pattern="^\d{8}" style="width: 180px;">
                                                        <button type="button" style="width: 3em" onclick="mostrarNombre('mostrarDECLARANTE')">:::</button>
                                                    </td>
                                                    <td colspan="4"><input type="text" name="nomDeclarante" id="DECLARANTE"   style="width: 450px;font-weight: bold;">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td><label/>DNI Persona Reg</td>
                                                    <td><input type="text" name="DNIPerReg" id="dniPERSREG" maxlength="8" pattern="^\d{8}" style="width: 180px;">
                                                        <button type="button" style="width: 3em" onclick="mostrarNombre('mostrarPERSONAREG')">:::</button>
                                                    </td>
                                                    <td colspan="4"><input type="text" name="nomRegistrador" id="registrador" style="width: 450px;font-weight: bold;">
                                                    </td>
                                                </tr>
                                            </table>
                                        </fieldset>
                                        <fieldset><legend>OTROS</legend>
                                            <table>
                                                <tr>
                                                    <td><label/>Cod Estado</td>
                                                    <td><select name="CodEst" id="codest" style="width: 140px;padding: 7px 6px;
                                                                border: 1px solid #CED5D7;
                                                                resize: none;
                                                                box-shadow:0 0 0 3px #EEF5F7;
                                                                margin: 5px 0;
                                                                text-transform: uppercase;">
                                                            <%LinkedList<Estado> listaEstado = Lista.getListaEstado();
                                                                for (int le = 0; le < listaEstado.size(); le++) {%>
                                                            <option value="<%=listaEstado.get(le).getCOD_ESTADO()%>"><%=listaEstado.get(le).getNOM_ESTADO()%></option>
                                                            <%}
                                                            %>
                                                        </select>
                                                    </td>

                                                    <td><label/>Cod Tipo Documento</td>
                                                    <td><select name="CodTDoc" id="codtdoc" style="padding: 7px 6px;
                                                                width: 160px;
                                                                border: 1px solid #CED5D7;
                                                                resize: none;
                                                                box-shadow:0 0 0 3px #EEF5F7;
                                                                margin: 5px 0;
                                                                text-transform: uppercase;">
                                                            <%LinkedList<TipoDocumento> lDoc = Lista.getlistatDocumento();
                                                                for (int d = 0; d < lDoc.size(); d++) {%>
                                                            <option value="<%=lDoc.get(d).getCOD_T_DOC()%>"><%=lDoc.get(d).getNOM_T_DOC()%></option>
                                                            <%}
                                                            %>
                                                        </select>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td><label/>Ruta Acta De Defuncion</td>
                                                    <td>
                                                        <input type="file" name="RutActDef" id="rutActDe" maxlength="100" style="width: 130px;">
                                                    </td>
                                                    <td><label/>Ruta Acta De Defuncion 2</td>
                                                    <td>
                                                        <input type="file" name="RutActDef2" id="rutActDe2" maxlength="100" style="width: 130px;">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td><label/>Observaciones</td>
                                                    <td><input type="text" name="Obs" id="ob" maxlength="100" style="width: 200px;">
                                                    </td>
                                                </tr>

                                            </table>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4">
                                        <div align="center">                  
                                            <fieldset style="alignment-baseline: central; height: 4em">
                                                <legend style="border: 1px solid #dce0e3;background-color: #edf1f5">BOTONES DE MANTENIMIENTO</legend>
                                                <table align="center" border="0">
                                                    <tr>
                                                        <td><button type="submit" name="btn1" value="guardaDef" onclick="main()" class="boton">Guardar</button></td>
                                                        <td><button type="reset" name="btn1" value="menu">Menu Principal</button></td>
                                                        <td><button type="button" name="btn1" onclick="main()" value="salir" class="">Salir</button></td>
                                                    </tr>
                                                </table>
                                            </fieldset>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <%String msj = (String) request.getAttribute("msj");
                                            if (msj != null) {
                                                if (msj == "1") {%>
                                        <div>
                                            <fieldset style="border-radius: 10px 10px 10px 10px; background-color: #fff5f6;border:1px solid #f57269">
                                                <legend style="border-radius: 10px 10px 10px 10px; background-color: #fff5f6;border:1px solid #f57269"><img src="/RegCivil/imagenes/exclamation.png"> </legend>
                                                <label>Error en almacenar el registro ingresado</label>
                                            </fieldset>
                                        </div>
                                        <%}
                                            if (msj == "2") {%>
                                        <div>
                                            <fieldset style="border-radius: 10px 10px 10px 10px; background-color: #d0e7ff;border:1px solid #61b0ff">
                                                <legend style="border-radius: 10px 10px 10px 10px; background-color: #d0e7ff;border:1px solid #61b0ff"><img src="/RegCivil/imagenes/info.png"> </legend>
                                                <label>El Registro se almaceno Correctamente</label>
                                            </fieldset>
                                        </div>
                                        <%}
                                        %>
                                        <%} else {%>
                                        <div>
                                            <fieldset style="border-radius: 10px 10px 10px 10px; background-color: #fffbe7;border:1px solid #ffe954">
                                                <label style="color:#edd00c; font-size: 1.0em ">Informacion de Almacenamiento</label>
                                            </fieldset>
                                        </div>
                                        <%}%>
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                    </td>
                </tr>

            </table>
        </form>


        <div id="NAVUbigeo" title="Lista De Ubigeos">
            <table>
                <tr>
                    <td><label/>Departamento</td>
                    <td><input type="text" name="Tdepartamento" id="Tdep" onkeyup="AUbigeo('Ubigeo')"/></td>
                    <td><label/>Provincia</td>
                    <td><input type="text" name="Tprovincia" id="Tpro" onkeyup="AUbigeo('Ubigeo')"/></td>
                    <td><label/>Distrito</td>
                    <td><input type="text" name="Tdistrito" id="Tdis" onkeyup="AUbigeo('Ubigeo')"/></td>
                    <td><label/>Otro</td>
                    <td><input type="text" name="Totro" id="Totr" onkeyup="AUbigeo('Ubigeo')"/></td>
                </tr>
            </table>
            <table>
                <thead>
                    <tr>
                        <th>id_ubigeo_dep</th>
                        <th>id_ubigeo_prov</th>
                        <th>id_ubigeo_dist</th>
                        <th>id_ubigeo_otro</th>
                        <th>nom_ubigeo_dep</th>
                        <th>nom_ubigeo_prov</th>
                        <th>nom_ubigeo_dist</th>
                        <th>nom_ubigeo_otro</th>
                    </tr>
                </thead>
                <tbody id="listaU">
                    <% LinkedList<Ubigeo> lUbig = Lista.getListaUbigeo();
                        for (int lu = 0; lu < lUbig.size(); lu++) {%>
                    <tr id="<%=lUbig.get(lu).getIDUBIGEO()%>">
                        <td align="center"><%=lUbig.get(lu).getIDUBIGEODEP()%></td>
                        <td align="center"><%=lUbig.get(lu).getIDUBIGEOPROV()%></td>
                        <td align="center"><%=lUbig.get(lu).getIDUBIGEODIST()%></td>
                        <td align="center"><%=lUbig.get(lu).getIDUBIGEOOTRO()%></td>
                        <td align="center"><%=lUbig.get(lu).getNOMUBIGEODEP()%></td>
                        <td align="center"><%=lUbig.get(lu).getNOMUBIGEOPROV()%></td>
                        <td align="center"><%=lUbig.get(lu).getNOMUBIGEOSDIST()%></td>
                        <td align="center"><%=lUbig.get(lu).getNOMUBIGEOOTRO()%></td>
                        <td align="center"><input type="image" name="seleccionar" src="/RegCivil/imagenes/apply.png" alt="borrar" value="<%=lUbig.get(lu).getIDUBIGEO()%>" onclick="selectUbigeo(this)"/></td>
                    </tr>
                    <%}%>
                </tbody>
            </table>
        </div>
    </body>
</html>

